package net.findkrypton.event;

import javafx.scene.image.Image;
import javafx.scene.input.MouseButton;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import net.findkrypton.GameInfo;
import net.findkrypton.enume.Level;
import net.jumpengine.Manager;
import net.jumpengine.bean.Base;
import net.jumpengine.bean.ButtonBase;
import net.jumpengine.bean.ImageBase;
import net.jumpengine.bean.TextBase;
import net.jumpengine.enume.GameState;
import net.jumpengine.inter.IAction;
import net.jumpengine.inter.IStateEvent;
import net.jumpengine.manager.ImageManager;
import net.jumpengine.po.Border;
import net.jumpengine.util.UIO;

public class StartStateEvent implements IStateEvent {
	private boolean load=false;
	private ButtonBase loadBtu;
	private ButtonBase easy,nomal,hard;
	private boolean visible=true;

	@Override
	public boolean isLoaded() {
		return load;
	}

	@Override
	public void load() {
		Border border=new Border(6, 10, 4, 7, 6);
		border.setMoveIn(Color.BROWN);
		Font font=new Font("黑体",40);
		
		ImageManager im = Manager.getImageManager();

		ButtonBase btu=new ButtonBase(40, 450, 211, 70,border, "开始游戏");
		btu.setFont(font);
		btu.setAction(new IAction() {
			@Override
			public void handle(int x, int y, MouseButton button, Base base) {
				setVisible(visible);
				visible=!visible;
			}
		});
		im.add(btu);
		
		loadBtu=new ButtonBase(40, 540, 211, 70,border, "读取游戏");
		loadBtu.setFont(font);
		loadBtu.setAction(new IAction() {
			@Override
			public void handle(int x, int y, MouseButton button, Base base) {
				Manager.setState(GameState.load, true);				
			}
		});
		im.add(loadBtu);
		
		btu=new ButtonBase(40, 630, 211, 70,border, "帮助");
		btu.setFont(font);
		btu.setAction(new IAction() {
			@Override
			public void handle(int x, int y, MouseButton button, Base base) {
				Manager.setState(GameState.help);
			}
		});
		im.add(btu);
		
		btu=new ButtonBase(40, 720, 211, 70,border, "退出游戏");
		btu.setFont(font);
		btu.setAction(new IAction() {
			@Override
			public void handle(int x, int y, MouseButton button, Base base) {
				System.exit(0);
			}
		});
		im.add(btu);
		
		IAction action=new IAction() {
			@Override
			public void handle(int x, int y, MouseButton button, Base base) {
				Level level=null;
				if(base==easy) {
					level=Level.easy;
				}else if(base==nomal) {
					level=Level.nomal;
				}else {
					level=Level.hard;
				}
				
				IStateEvent stateEvent = Manager.getEventManager().getStateEvent(GameState.running);
				RunningStateEvent run=(RunningStateEvent) stateEvent;
				GameInfo info = run.getInfo();
				if(info==null) {
					info=new GameInfo(level);
					run.setInfo(info);
				}else {
					info.setLevel(level);	
					run.getArray().reset();
				}
				
				setVisible(false);
				visible=true;
				Manager.setState(GameState.running);
			}
		};
		
		border=new Border(2, 2, 2, 2, 2);
		Font f=new Font("黑体",25);
		easy=new ButtonBase(280, 470, 81, 41,border, "入门");
		easy.setFont(f);
		easy.setAction(action);
		im.add(easy);
		
		nomal=new ButtonBase(380, 470, 81, 41,border, "正常");
		nomal.setFont(f);
		nomal.setAction(action);
		im.add(nomal);
		
		hard=new ButtonBase(480, 470, 81, 41,border, "困难");
		hard.setFont(f);
		hard.setAction(action);
		im.add(hard);
		setVisible(false);
		
		Image image = UIO.loadImage("/start/GameBox.png",this.getClass());
		ImageBase base=new ImageBase(0, 10, image);
		im.add(base);
		
		image = UIO.loadImage("/start/GameLogo.png",this.getClass());
		base=new ImageBase(580, 10, image);
		im.add(base);
		
		image = UIO.loadImage("/start/wushi.png",this.getClass());
		base=new ImageBase(790, 220, image);
		im.add(base);
		
		String str="  在魔法界,氪金是一种广泛使用的材料.但其遇到空气就会燃烧爆炸的特性使得氪金的开采一直效率低下.直到大魔法师墨菲托斯·拉布拉多发明了占卜术加方块消除术标记氪金所在的岩石,以会方块消除术的学徒清理普通岩石的方法.使得氪金的开采变的容易许多.\n" + 
				"  现在,需要你去开采一处氪金矿石.";
		TextBase text=new TextBase(370, 570,771, str,3,new Font("黑体",29));
		im.add(text);
		
		load=true;
	}
	
	@Override
	public void show() {
		
	}
	
	private void setVisible(boolean visible) {
		easy.setVisible(visible);
		nomal.setVisible(visible);
		hard.setVisible(visible);
	}

	@Override
	public void pause() {
		// TODO Auto-generated method stub

	}

	@Override
	public void end() {
		// TODO Auto-generated method stub

	}

	public ButtonBase getLoadBtu() {
		return loadBtu;
	}

	@Override
	public void setBackImage(Image image) {
		// TODO Auto-generated method stub
		
	}


}
